
import useStore from '../store/index'
export const languageData = ['中文','English']
export function getLocale(): string {
  let lan = ''
  switch (useStore.getters.getLanguage) {
    case '中文':
      lan = 'zh'
      break;
    case 'English':
      lan = 'en'
      break;
    default:
      break;
  }
  return lan
}
// 深拷贝
export function deepClone(source: any) {
  if (!source || typeof source !== 'object') {
    return source
    // throw new Error('error arguments', 'shallowClone')
  }
  const targetObj:any = source.constructor === Array ? [] : {}
  Object.keys(source).forEach(keys => {
    if (source[keys] && typeof source[keys] === 'object') {
      targetObj[keys] = deepClone(source[keys])
    } else {
      targetObj[keys] = source[keys]
    }
  })
  return targetObj
}

/**
 * json数组去重
 * @param {Array} array 需要去重的数组
 * @param {String} key  根据key字段去重
 */
 
 export function uniqueArray(array: Array<any>, key: string) {
  const result = [array[0]]
  for (let i = 1; i < array.length; i++) {
    const item = array[i]
    let repeat = false
      for (let j = 0; j < result.length; j++) {
          if (item[key] === result[j][key]) {
              repeat = true
              break
          }
      }
      if (!repeat) {
          result.push(item);
      }
  }
  return result
}